package com.simple.core.rest;

import com.simple.core.controller.BaseController;
import com.simple.core.dto.PageDto;
import com.simple.core.dto.Response;
import com.simple.core.log.SysLogService;
import com.simple.core.log.SysLogs;
import io.swagger.annotations.Api;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.io.Serializable;
import java.util.List;

/**
 * @author FanXing
 * @date 2023年02月01日 15:18
 */
@Api(tags = "日志管理")
@RestController
@RequestMapping("/sysLog")
public class SysLogController extends BaseController<SysLogs, SysLogService> {
    @Override
    protected PageDto<SysLogs> defaultPage(SysLogs sysLogs, PageDto<SysLogs> pageDto) {
        return service.page(Specification.where((root, query, criteriaBuilder) ->
                criteriaBuilder.and(
                        criteriaBuilder.like(root.get("method"), "%" + sysLogs.getMethod() + "%"),
                        criteriaBuilder.greaterThanOrEqualTo(root.get("createdTime"), sysLogs.getCreatedTimeStart()),
                        criteriaBuilder.lessThanOrEqualTo(root.get("createdTime"), sysLogs.getCreatedTimeEnd())
                )
        ), pageDto);
    }

    @ApiIgnore
    @Override
    public Response<PageDto<SysLogs>> slice(SysLogs sysLogs, PageDto<SysLogs> pageDto) {
        return super.slice(sysLogs, pageDto);
    }

    @ApiIgnore
    @Override
    public Response<Boolean> add(SysLogs sysLogs) {
        return super.add(sysLogs);
    }

    @ApiIgnore
    @Override
    public Response<Boolean> update(SysLogs sysLogs) {
        return super.update(sysLogs);
    }

    @ApiIgnore
    @Override
    public Response<Boolean> delete(List<Serializable> ids) {
        return super.delete(ids);
    }

}
